<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class Exchange_rate_model  extends MY_Model  {

    public $table = 'exchange_rates';

	public function __construct() {
		$this->class_name = get_class ( $this );
		parent::__construct( $this->class_name, $this->table );
		parent::init( $this->class_name, $this->table );
	}
	
	public function get_rate_by_currency($currency, $date=''){
			
		$where = 'currency = "' . (int) $currency . '"';
		
		if (!empty($date)){
			$where .= ' AND date = "' . $date . "'";
		}

		$this->db->order_by('date','desc');
        $result =  $this->db->select()->where($where)->get($this->table,1)->row();
        $obj = FALSE;
        if ($result) {
            $obj = $this->from_array((array)$result);
        }
      
        return $obj;
	}
}